package datenbank;

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

public class DBObject{

  private static final String DEFAULT_CONNECTION_TYPE = "oracle";

  public Connection get_connection() {
    return get_connection(DEFAULT_CONNECTION_TYPE);
  }
    
  public Connection get_connection(String dbtype) {
	System.out.println ("Hallo ich bin get_connection() in der DBObject.java");
    final String propfile = "/properties/db_oracle.properties";

    System.out.println ("DBObject.get_connection dbtype="+propfile);
    Connection cn = null;
    try {
      final java.io.InputStream propFile = getClass().getResourceAsStream(propfile);
      final Properties props = new Properties(System.getProperties());
      props.load(propFile);

      Class.forName(props.getProperty("driver"));

      final String usr = props.getProperty("user");
      final String pwd = props.getProperty("password");
      final String url = props.getProperty("url");

      cn = DriverManager.getConnection(url, usr, pwd);
      cn.setAutoCommit(false);
      cn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
    } catch (Exception e) {
      System.err.println("DBObject.get_connection: Problem beim DB-Verbindungsaufbau:\n"
                         + e.toString());
    }
    return cn;
  }
}
